home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
turbovis
/
tvtool17.zip
/
TVTOOLS.ZIP
/
INDOUBLE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-19
|
3KB
|
115 lines
/* Copyright (C) 1993 Marc Stern (internet: stern@mble.philips.be) */
#define Uses_TStreamable
#define Uses_MsgBox
#define Uses_TInputDouble
#include "tvtools.h"
__link( RInputLine )
#include <string.h>
#include <stdio.h>
#include <values.h>
#include <stdlib.h>
#include <strstream.h>
// TInputDouble
const char * const TInputDouble::name = "TInputDouble";
void TInputDouble::write( opstream& os )
{
TInputLine::write( os );
os << min;
os << max;
}
void *TInputDouble::read( ipstream& is )
{
TInputLine::read( is );
is >> min;
is >> max;
return this;
}
TStreamable *TInputDouble::build()
{
return new TInputDouble( streamableInit );
}
TStreamableClass RInputDouble( TInputDouble::name,
TInputDouble::build,
__DELTA(TInputDouble)
);
TInputDouble::TInputDouble( const TRect& bounds,
int aMaxLen,
double aMin,
double aMax
)
:TInputRegExp( bounds, aMaxLen, "-.0-9eE" )
{
min = aMin;
max = aMax;
}
TInputDouble::TInputDouble( int x, int y,
int aMaxLen,
double aMin,
double aMax
)
:TInputRegExp( x, y, aMaxLen, "-.0-9eE" )
{
min = aMin;
max = aMax;
}
ushort TInputDouble::dataSize()
{
return sizeof( double );
}
void TInputDouble::getData( void *rec )
{
*(double *)rec = atof( data );
}
void TInputDouble::setData( void *rec )
{
char buffer[256];
sprintf( buffer, "%G", *(double *)rec );
strncpy( data, buffer, maxLen );
data[maxLen] = EOS;
selectAll(True);
}
Boolean TInputDouble::valid( ushort command )
{
switch( command )
{
case cmReleasedFocus: return True;
case cmQuit :
case cmClose:
case cmOK : double value = atof( data );
if ( (! *data) || (value < min) || (value > max) )
{
select();
messageBox( mfError | mfOKButton,
"\03Number must be between %G and %G.",
min, max
);
selectAll( True );
return False;
}
break;
}
return TInputRegExp::valid( command );
}